package com.reny.ll.git.base_logic.ext

import kotlinx.coroutines.*

fun Any.delay(timeMillis: Long, func:() -> Unit): Job {
    return GlobalScope.launch {
        delay(timeMillis)
        withContext(Dispatchers.Main) {
            func()
        }
    }
}

fun Any.interval(maxSeconds:Int = 60, func:(Int)->Unit): Job{
    return GlobalScope.launch {
        for (i in maxSeconds downTo 0){
            withContext(Dispatchers.Main) {
                func(i)
            }
            delay(1000L)
        }
    }
    /*val timer = Observable.interval(0,1, TimeUnit.SECONDS).take(maxSeconds)
        .subscribe {
            callback(it)
        }*/
}